// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import moment from 'vue-moment'
import mandMobile from 'mand-mobile'
import 'mand-mobile/lib-vw/mand-mobile.css'
import VueAMP from 'vue-amap'
import Vuex from 'vuex'
import Axios from 'axios'
import Croppa from 'vue-croppa'
import VueQrcode from '@xkeshi/vue-qrcode'
import VeeValidate from 'vee-validate'

Vue.component(VueQrcode.name, VueQrcode)

Vue.use(mandMobile)
Vue.use(VeeValidate)
Vue.config.productionTip = false
Vue.use(moment)
Vue.use(mandMobile)
Vue.use(Vuex)
Vue.use(VueAMP)
Vue.use(Croppa)

const mxAxiosConfig = Axios.create({
  // baseURL: 'http://127.0.0.1:7001',
  baseURL: 'http://tmc.guotaijinxing.com',
  headers: {
  }
})

Vue.prototype.$api = mxAxiosConfig

/* Vuex */
const store = new Vuex.Store(
  {
    state: {
      order: {
        sdate: new Date(),
        edate: new Date()
      },
      wxuser: {},
      feetander: {
        insurance_fee: 100,
        service_fee: 50,
        driver_over_fee: 30,
        over_hour_fee: 60
      },
      flight: {
        cid: '',
        type: 0,
        address: '',
        stime: '',
        flightnum: '',
        lxname: '',
        lxphone: ''
      },
      agent: {
        uid: ''
      }
    },
    mutations: {
      updateOrder: function (state, res) {
        for (const v in res) {
          state.order[v] = res[v]
        }
      },
      updateUser: async function (state, res) {
        state.wxuser = res
      },
      updateFlight: function (state, res) {
        for (const v in res) {
          state.flight[v] = res[v]
        }
      },
      updateAgent: async function (state, uid) {
        let _oid = window.localStorage.getItem('agent_oid')
        if (!_oid) return false
        let res = await mxAxiosConfig.post('/fx/getagentinfo', {oid: _oid})
        if (res.data.state) {
          console.log(res.data.data)
          state.agent = res.data.data
        }
      }

    },
    actions: {
      getUser: async function (context) {
        let _oid = window.localStorage.getItem('wxopenid')
        if (!_oid) {
          return false
        }
        let _u = await mxAxiosConfig.post('/getu', {openid: _oid})
        if (_u.data.state) {
          context.commit('updateUser', _u.data.data)
        }
      }
    }
  }
)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
